home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 312 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Const and Non-Const Constructors
  5. Date: 07 Feb 1996 10:25:20 PST
  6. Organization: Comp Sci, University of Melbourne
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4f9pkj$av7@mulga.cs.mu.OZ.AU>
  9. References: <smeyersDMBEsy.5M8@netcom.com>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 7 Feb 1996 08:58:59 GMT
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMRjupUy4NqrwXLNJAQFXLAIAkl8F8DwwzwVaxJMMK6P/kz8zYAA9k0JY
  14.     YKYi+thMWgp/ICw9VJ1uJtSFeCcbb3rwdrEoQmY3TpPfEXbpgqDqsA==
  15.     =dH3W
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. smeyers@netcom.com (Scott Meyers) writes:
  19.  
  20. >A few months ago there was a discussion of whether the language should be
  21. >extended so that const and non-const objects would have different
  22. >constructors, the idea being that initialization for a const object might
  23. >be different from initialization for a non-const object.  My understanding
  24. >is the committee has rejected that idea.  Could someone please post a
  25. >summary of the problems with the idea or point me to a place where I can
  26. >find them?
  27.  
  28. One immediate problem is that to do it right would break backwards
  29. compatibility, because you should not be able to invoke a non-const
  30. constructor for a const object, just as you can't invoke a non-const
  31. member function for a const object.  Code such as
  32.  
  33.     struct X { int a; X(); };
  34.     const X x;
  35.  
  36. would have to be declared illegal, to be replaced with
  37.  
  38.     struct X { int a; X() const; };
  39.     const X x;          ^^^^^
  40.  
  41. Breaking backwards compatibility like this would be a real problem.
  42.  
  43. There are other problems (e.g. initialization of arrays may become
  44. very tricky) but I think the above problem would be sufficient to kill
  45. the proposal.
  46.  
  47. --
  48. Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  49. fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  50. ---
  51. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  52.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  53.   in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
  54.